package org.boulderfoodrescue.webapp.client.old.event;

import org.boulderfoodrescue.webapp.shared.UserAccount;

import com.google.gwt.event.shared.GwtEvent;

public class UserChangedEvent extends GwtEvent<UserChangedHandler>{

  private static final Type<UserChangedHandler> TYPE = new Type<UserChangedHandler>();
  private UserAccount user;
  private Boolean added;

  public UserChangedEvent(UserAccount user, Boolean added) {
    this.user = user;
    this.added = added;
  }

  public static Type<UserChangedHandler> getType() {
    return TYPE;
  }

  @Override
  public com.google.gwt.event.shared.GwtEvent.Type<UserChangedHandler> getAssociatedType() {
    return TYPE;
  }

  @Override
  protected void dispatch(UserChangedHandler handler) {
    if(added == null)
      handler.onUserUpdate(this);
    else if(added)
      handler.onUserAdd(this);
    else
      handler.onUserRemoved(this);
  }

  public UserAccount getUser() {
    return user;
  }

  public Boolean getAdded() {
    return added;
  }
}